package study05;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Java02_Copy {
    public static void main(String[] args) throws Exception {
//        数据源文件
        File srcFile = new File("D:\\java_study\\java_study\\data\\word.txt");
//        数据目的地文件(自动生成文件)
        File destFile = new File("D:\\java_study\\java_study\\data\\test.txt.copy");
        //    文件输入流
        FileInputStream in = null;
        //    文件输出流
        FileOutputStream out = null;
        try {
            in = new FileInputStream(srcFile);
            out = new FileOutputStream(destFile);

//            打开阀门流转数据（输入）
            int data = -1;
//            打开阀门流转数据（输出）
//            out.write(data);
            while ((data = in.read()) != -1) {
                out.write(data);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
    }
}
